package com.soft.mainsite.module.data.dto;

import com.soft.mainsite.module.data.entity.Appointment;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * AppointmentDto.java 此类用于预约dto
 *
 * @author:李昭阳
 * @date:2019/4/24 0024
 * @remark:
 */
@EqualsAndHashCode(callSuper = false)
@Data
public class AppointmentDto extends Appointment {

    /**
     * 实体类列表转dto列表
     * @param entityList
     * @return
     */
    public static List<AppointmentDto> convertEntityToDtos(List<Appointment> entityList) {
        List<AppointmentDto> dtoList = new ArrayList<>();
        for (Appointment entity : entityList) {
            if (entity == null) {
                continue;
            }
            dtoList.add(convertEntityToDto(entity));
        }
        return dtoList;
    }

    /**
     * 实体类转dto
     * @param entity
     * @return
     */
    public static AppointmentDto convertEntityToDto(Appointment entity) {
        AppointmentDto dto = new AppointmentDto();
        BeanUtils.copyProperties(entity, dto);
        return dto;
    }

    /**
     * dto列表转实体类列表
     * @param dtoList
     * @return
     */
    public static List<Appointment> convertDtoToEntitys(List<AppointmentDto> dtoList){
        List<Appointment> entityList = new ArrayList<>();
        for (AppointmentDto dto : dtoList) {
            if(dto == null){
                continue;
            }
            entityList.add(convertDtoToEntity(dto));
        }
        return entityList;
    }

    /**
     * dto转实体类
     * @param dto
     * @return
     */
    public static Appointment convertDtoToEntity(AppointmentDto dto) {
        Appointment entity = new Appointment();
        BeanUtils.copyProperties(dto, entity);
        return entity;
    }
}
